<template>
    <div class="RxPortal">
        <div v-for="(portal,index) in colList" :key="index">
            <rx-wheel-img v-if="portal.type=='wheel'" :portal="portal"></rx-wheel-img>
            <rx-grid v-else-if="portal.type=='grid' || portal.type=='largeScreen'" :portal="portal"></rx-grid>
            <rx-process v-else-if="portal.type=='process'" :portal="portal"></rx-process>
            <rx-news v-else-if="portal.type=='notice'" :num="portal.noticeNum"></rx-news>
            <rx-gridTab v-else-if="portal.type=='tab'" :portal="portal"></rx-gridTab>
        </div>
        <view class="rx-empty" v-if="colList.length==0">
            <img src="@/static/empty.png"/>
            <span class="rx-empty-name">{{i18n('configureMobile','请前往平台门户中心配置移动门户')}}</span>
        </view>
    </div>
</template>

<script>
import RxWheelImg from "@/pages/RxGateway/RxWheelImg";
import RxGrid from "@/pages/RxGateway/RxGrid";
import RxProcess from "@/pages/RxGateway/RxProcess";
import RxNews from "@/pages/RxGateway/RxNews";
import RxGridTab from "@/pages/RxGateway/RxGridTab";
import RxCustomColumn from "@/pages/RxGateway/RxCustomColumn";
import Constants from '@/common/constants.js'
import TokenUtil from "../../common/TokenUtil";

export default {
    name: "RxPortal",
    data() {
        return {
            colList: [],
            curUser: {}
        }
    },
    provide() {
        return {
            portalJump: this.portalJump
        }
    },
    props: {
        portal: Object,
    },
    components: {
        RxWheelImg,
        RxGrid,
        RxProcess,
        RxNews,
        RxGridTab,
        RxCustomColumn
    },
    created() {
        this.init()
        this.curUser = uni.getStorageSync("user");
    },
    mounted() {

    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "mobileLang", key);
        },
        init() {
            let html = this.portal.layoutHtml;
            if (html) {
                this.colList = JSON.parse(html);
            }
        },
        /**
         * item.appId
         * @param item
         */
        portalJump(item) {
            let mobileAppId = uni.getStorageSync("mobileAppId");
            let pathList = {
                 'myTasks':'/pages/RxProcessManagement/RxMyTasks/RxMyTasks',
                 'mySolutions':'/pages/RxProcessManagement/RxMySolutions/RxMySolutions',
                 'news':'/pages/RxProcessManagement/RxNews/RxNews',
                 'myInst':'/pages/RxProcessManagement/RxMyApplication/RxMyApplication',
                 'HasHandle':'/pages/RxProcessManagement/RxMyApprovedTasks/RxMyApprovedTasks',
                 'TransOutTask':'/pages/RxProcessManagement/RxMyTransOutTask/RxMyTransOutTask',
                 'ReceiveTask':'/pages/RxProcessManagement/RxMyReceiveTask/RxMyReceiveTask',
                 'MyTransmit':'/pages/RxProcessManagement/RxMyTransmit/RxMyTransmit',
                 'ReceiveTransmit':'/pages/RxProcessManagement/RxReceiveTransmit/RxReceiveTransmit',
                 'MyTracked':'/pages/RxProcessManagement/RxMyTracked/RxMyTracked',
                 'myPending':'/pages/RxProcessManagement/RxMyPending/RxMyPending',
                 'asynchronous':'/pages/RxProcessManagement/RxMyAsynchronous/RxMyAsynchronous',
                 'appPortal':'RxAppPortal',
                 'CustomList':'customList',
                 'CustomForm':'customForm',
                 'myCollection':'/pages/RxScreen/MyCollection',
                 'myShare':'/pages/RxScreen/MyShare',
                 'custom':'/views/customPage/customPage'
            }
            let params = {};
            let path = pathList[item.routeName];
            if(item.appId){
                if(Array.isArray(item.appId)){
                    item.appId.forEach(res=>{
                        mobileAppId = res.value
                    })
                }else {
                    mobileAppId = item.appId
                }
            }
            if(mobileAppId){
                uni.setStorage({key: "mobileAppId", data: mobileAppId})
            }
            switch (item.routeName) {
                case 'process':
                    //流程办理
                    params = {
                        defId: item.defId,
                        defKey: item.key,
                    }
                    if (mobileAppId) {
                        params['appId'] = mobileAppId
                    }
                    uni.navigateTo({
                        url: '/pages/RxProcessManagement/RxMyTasks/RxMyTasks?params=' + JSON.stringify(params)
                    });
                    break;
                case 'StartForm':
                    params = {
                        defId: item.defId,
                        defKey: item.key,
                        routerName: 'newDoc',
                        action: 'edit'
                    }
                    uni.navigateTo({
                        url: '/views/modules/bpm/OpenDoc?params=' + JSON.stringify(params)+ '&appId=' + mobileAppId
                    })
                    break;
                case 'appPortal':
                    uni.navigateTo({
                        url: '/pages/RxAppPortal/RxAppPortal'
                    });
                    break;
                case 'CustomList':
                    //列表
                    params = {
                        alias: item.key,
                        pmtAlias: item.pmtAlias
                    }
                    if (mobileAppId) {
                        params['appId'] = mobileAppId;
                    }
                    uni.navigateTo({
                        url: '/views/modules/form/customList/CustomList?params=' + JSON.stringify(params)
                    })
                    break;
                case 'CustomForm':
                    //表单方案
                    params = {
                        alias: item.alias,
                        action: 'edit'
                    }
                    if (mobileAppId) {
                        params['appId'] = mobileAppId
                    }
                    uni.navigateTo({
                        url: '/views/modules/form/customForm/FormSolutionShow/FormSolutionComponent?params=' + JSON.stringify(params)
                    })
                    break;
                case 'rxUreport':
                    let wPath = window.document.location.origin;
                    let token = TokenUtil.getToken();
                    let obj = wPath + '/ureport/preview?_u=qiaolin-' + item.alias + '&accessToken=' + token + '&appId=' + mobileAppId;
                    let url = '/pages/RxIframe/RxIframe?url=' + obj;
                    uni.navigateTo({
                        url: url
                    })
                    break;
                case 'IFrame':
                    uni.navigateTo({
                        url: '/pages/RxIframe/RxIframe?url=' + item.url
                    })
                    break;
                case 'customView':
                    //页面定制
                    params = {
                        alias: item.alias,
                        title: item.title
                    }
                    uni.navigateTo({
                        url: '/views/modules/form/FormCustomView/FormCustomView?params=' + JSON.stringify(params) + '&appId=' + mobileAppId
                    })
                    break;
                case 'custom':
                    //自定义页面
                    params = {
                        customModule: item.customModule,
                        title: item.title
                    }
                    uni.navigateTo({
                        url: '/views/customPage/customPage?params=' + JSON.stringify(params) + '&appId=' + mobileAppId
                    })
                    break;
                case 'customFun':
                    this.execCustomFun(item)
                default:
                    if (mobileAppId) {
                        path  =path+'?appId='+mobileAppId
                    }
                    uni.navigateTo({
                        url: path
                    });


            }

        },
        execCustomFun(item){
            if (!(item && item.JSScript)){
                this.$message.error("未配置JS脚本");
                return;
            }
            let fn=new Function("item",item.JSScript).bind(this);
            let rtn= fn(item);
        },
    }
}
</script>

<style scoped>
.RxPortal {
    height: 100%;
    overflow: auto;
}
.rx-empty{
    width: 100%;
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 3rem;
}
.rx-empty img{
    width: 17rem;
}
.rx-empty-name{
    font-size: 0.8rem;
    margin-top: -1rem;
    text-align: center;
    width: 80%;
    color: rgb(122, 126, 131);
}
</style>
